import js from '@eslint/js'; //推荐校验js规范
import globals from 'globals';
import pluginVue from 'eslint-plugin-vue'; //推荐校验vue规范
import { defineConfig } from 'eslint/config';
import prettierRecommended from 'eslint-plugin-prettier/recommended';
// 引入自动导入的配置文件
// import autoImport from './.eslintrc-auto-import.json' with { type: 'json' };

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const autoImport = require('./.eslintrc-auto-import.json');

export default defineConfig([
  {
    files: ['**/*.{js,mjs,cjs,vue}'],
    plugins: { js },
    extends: ['js/recommended'],
  },
  {
    files: ['**/*.{js,mjs,cjs,vue}'],
    languageOptions: {
      globals: {
        ...globals.node,
        ...globals.browser,
        ...globals.es2021,
        ...autoImport.globals,
      },
    },
  },
  pluginVue.configs['flat/essential'],
  {
    // 忽略Eslint校验的文件
    ignores: ['dist', 'node_modules'],
  },
  {
    // 自定义校验规则
    rules: {
      'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
      'vue/multi-word-component-names': 'off',
      semi: ['error', 'always'], // 强制使用分号
    },
  },
  prettierRecommended, // 继承prettier的校验规则
]);
